﻿
/**
* 命名空间: Assets.Scripts.TDBehavior
*
* 功 能： N/A
* 类 名： TDBehaviorSystem
*
* Ver 变更日期 负责人 变更内容
* ───────────────────────────────────
* V0.01 2019/12/16 13:58:24  
*/




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using Game.TDBehaviorTree;
using System.IO;

namespace Game.TDBehaviorTree
{
    public class TDBehaviorSystem : MonoBehaviour
    {
        public static TDBehaviorSystem Instance;
        public NodeBase m_CurrentNode=null;

        private void Awake()
        {
            Instance = this;
        }


        private void Update()
        {
            if (m_CurrentNode != null)
            {
                NodeResultType resultType = m_CurrentNode.Execute();
                if (resultType == NodeResultType.Success)
                {
                    if (m_CurrentNode.NodeCompleteAction != null)
                    {
                        m_CurrentNode.NodeCompleteAction();
                    }
                    Debug.Log("行为结束");
                    m_CurrentNode = null;
                }else if (resultType == NodeResultType.Fail)
                {
                    Debug.Log("行为失败");
                    m_CurrentNode = null;
                }
            }

        }

        public NodeBase LoadBehaviorTree(string filename,GameObject _SetObj)
        {
            NodeBase node = new NodeBase();
            JsonDataParser.ReadJson<NodeBase>(filename, out node);
            node.Agent = _SetObj;
            node.NodeCompleteAction += () => { Debug.Log("<color=red>行为执行成功</color>"); };
            return node;
        }


    }
}
